#!/bin/bash
# init file for ganesha
#
# chkconfig: - 50 50
# description: GANESHA NFS Daemon
#
# processname: /opt/hpss/hpss.ganesha.nfsd
# config: /var/hpss/etc/hpss.ganesha.nfsd.conf
# pidfile: /var/run/snmpd

# source function library
. /etc/init.d/functions

PATHPROG=/opt/hpss/bin/hpss.ganesha.nfsd 

# Default HPSS options
LOGFILE=/var/hpss/nfs/ganesha.log
CONFFILE=/var/hpss/etc/hpss.ganesha.nfsd.conf

OPTIONS="-d -L $LOGFILE -f $CONFFILE -N NIV_EVENT"
RETVAL=0
prog="hpss.ganesha.nfsd"

start() {
        echo -n $"Starting $prog: "
        if [ $UID -ne 0 ]; then
                RETVAL=1
                failure
        else
                daemon $PATHPROG $OPTIONS
                RETVAL=$?
                [ $RETVAL -eq 0 ] && touch /var/lock/subsys/hpss.ganesha.nfsd
        fi;
        echo 
        return $RETVAL
}

stop() {
        echo -n $"Stopping $prog: "
        if [ $UID -ne 0 ]; then
                RETVAL=1
                failure
        else
                killproc $PATHPROG
                RETVAL=$?
                [ $RETVAL -eq 0 ] && rm -f  /var/lock/subsys/hpss.ganesha.nfsd

        fi;
        echo
        return $RETVAL
}

reload(){
        echo -n $"Reloading $prog: "
        killproc $PATHPROG -HUP
        RETVAL=$?
        echo
        return $RETVAL
}

restart(){
	stop
	start
}

condrestart(){
    [ -e /var/lock/subsys/hpss.ganesha.nfsd ] && restart
    return 0
}

case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	restart
        ;;
  reload)
	reload
        ;;
  condrestart)
	condrestart
	;;
  status)
        status $prog
	RETVAL=$?
        ;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
	RETVAL=1
esac

exit $RETVAL
